package main

import (
	"fmt"
	"github.com/pkg/errors"
)

type User struct {
	ID int `json:"id"`
	Name string `json:"name"`
}


var NotFind = errors.New("sql.ErrNoRows")

func main() {

	//模拟数据库查询获取用户数据
	info,e := getUserById(10)
	if errors.Is(e,NotFind) {
		fmt.Printf("Original error: %T %v\n", errors.Cause(e),errors.Cause(e))
		fmt.Printf("stack trace: \n%+v\n", e)
		return
	}
	fmt.Println(info)
}

func getUserById(ID int) (Info User, err error)  {

	switch ID {
	case 1:
		return User{1,"张三"}, nil
	case 2:
		return User{1,"李四"}, nil
	default:
		return User{},errors.Wrap(NotFind,fmt.Sprintf("用户ID：%v",ID))
	}
}











